package cn.leedsoft.and.crimeintent.model;

import android.content.Context;
import android.media.MediaPlayer;
import cn.leedsoft.and.crimeintent.R;

/**
 * Created by leeds on 2016/8/9 17:45.
 */
public class AudioPlayer {
    private MediaPlayer mMediaPlayer;

    public void stop() {
        if(mMediaPlayer != null) {
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }

    public void play(Context context) {
        stop();
        mMediaPlayer = MediaPlayer.create(context, R.raw.one_small_step);
        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
               stop();
            }
        });
        mMediaPlayer.start();
    }
}
